﻿const chokidar = require('chokidar');
const { exec } = require('child_process');

// 监听的文件或文件夹路径
const watchPath = './ClientApp'; // 根据实际情况调整路径

// 执行的命令
const commandToRun = 'npm run build';

// 监听文件变化
chokidar.watch(watchPath).on('change', (path) => {
    console.log(`File ${path} has been changed`);

    // 在这里可以添加更多的逻辑判断，例如检测 Ctrl + S 按键事件

    // 执行命令
    exec(commandToRun, (error, stdout, stderr) => {
        if (error) {
            console.error(`exec error: ${error}`);
            return;
        }
        console.log(`Watching for changes in ${watchPath}...`);
    });
});

console.log(`Watching for changes in ${watchPath}...`);
